package com.cskaoyan.utils;

import com.cskaoyan.config.HashProperties;
import lombok.Data;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Data
@Component
public class PasswordGenerateUtil {

//    final static String SALT = "wd";
//    private final static Integer HASH_ITERATIONS = 2;

    static HashProperties hashProperties;

    @Autowired
    ApplicationContext applicationContext;
    @PostConstruct
    public void init() {
        PasswordGenerateUtil.hashProperties = applicationContext.getBean(HashProperties.class);
    }

    public static String getHashedPassword(String password) {
        Md5Hash md5Hash = new Md5Hash(password, hashProperties.getSalt(), hashProperties.getTimes());
        return md5Hash.toString();
    }
}